/****** Object:  Stored Procedure BulkOrdersGet    Script Date: Wednesday, November 21, 2007 ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spBulkOrdersGetDetails]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [spBulkOrdersGetDetails]
GO


CREATE PROCEDURE spBulkOrdersGetDetails
	@BulkOrderID int
AS

SELECT
	[BulkOrderID],
	[OrderDate],
	[Type],
	[ProductCode],
	[Description],
	[Color],
	[StartDate],
	[TotalQtyOrdered],
	[TotalQtyCompleted],
	[TotalQtyInProgressBelow50P],
	[TotalQtyInProgressAbove50P],
	[EstimatedDate],
	[StockLastCheckedDate],
	[StockLastCheckedQty],
	[FOB],
	[CompletedDate],
	[SupplierCode],
	[Owner],
	[Catalogue],
	[Page],
	[Pack],
	[PackQty],
	[CatalogID],
	[Target],
	[SalesDescription1],
	[SalesDescription2],
	[StockLocation],
	[AvailableInUSA],
	[BONo],
	[MinOrderQty],
	[TallPaletQty],
	[IDSSortID],
	[IsArchived],
	[CatPackDesc],
	[MUKTHGCatPackQty],
	[MUKTHGCatPackDesc],
	[HomeDelivered15Price],
	[CurrencyID],
	[IsShownInLGDCatalog],
	[SpecialOfferDisc],
	[ModifiedDate],
	([TotalQtyCompleted] - ISNULL((SELECT SUM(QtyIssued)
					FROM DeliveredOrders 
					WHERE [BulkOrders].[BulkOrderID] = DeliveredOrders.[BulkOrderID]), 0)) as QuantityAvailable
FROM
	[BulkOrders]
WHERE
	[BulkOrderID] = @BulkOrderID

GO
	

	
 